package com.atguigu.common.constant;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * mybatis-plus 自动插入
 */
@Component
public class MPMetaObjectHandler implements MetaObjectHandler {


    @Override
    public void insertFill(MetaObject metaObject) {
        setFieldValByName(MPMetaObjectConstant.CREATE_TIME, new Date(), metaObject);
        setFieldValByName(MPMetaObjectConstant.UPDATE_TIME, new Date(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        setFieldValByName(MPMetaObjectConstant.UPDATE_TIME, new Date(), metaObject);
    }
}
